#!/usr/bin/env python
#-*- encoding:UTF-8 -*-

# $Id$

import wx
import connDB

class CreateSDTMEditor:
    """
    Create some StaticText and TextCtrl for Editing SDTM dataset level metadata
    """
    
    def __init__(self, parent, classlst):
        
        [wxID_Dataset,
         wxID_Description,
         wxID_Class,
         wxID_Structure,
         wxID_Purpose,
         wxID_KeyVar,
         wxID_Comments,
         wxID_Version,
         wxID_Save,
         wxID_Discard,
         wxID_New,
         wxID_Close,
         wxID_Delete
        ] = [wx.NewId() for _init_ctrls in range(13)]
        
        #Class list    
        #classlst = connDB().classlst
        
        self.lb1 = wx.StaticText(parent, wx.ID_ANY, "Dataset:")
        self.te1 = wx.TextCtrl(parent, wxID_Dataset, "", size=(130, -1))
        # Dataset Name should not be editable
        self.te1.Disable()
        
        self.lb2 = wx.StaticText(parent, wx.ID_ANY, "Description:")
        self.te2 = wx.TextCtrl(parent, wxID_Description)
        
        self.lb3 = wx.StaticText(parent, wx.ID_ANY, "Class:")
        self.te3 = wx.ComboBox(parent, wxID_Class, size=(160, -1), choices=classlst)
        
        self.lb4 = wx.StaticText(parent, wx.ID_ANY, "Structure:")
        self.te4 = wx.TextCtrl(parent, wxID_Structure)
        
        #to-do: Purpose list
        purposelst=["Tabulation"]
        self.lb5 = wx.StaticText(parent, wx.ID_ANY, "Purpose:")
        self.te5 = wx.ComboBox(parent, wxID_Purpose, "Tabulation", size=(130, -1), choices=purposelst)
        
        self.lb6 = wx.StaticText(parent, wx.ID_ANY, "Key Variables:")
        self.te6 = wx.TextCtrl(parent, wxID_KeyVar)
        
        self.lb7 = wx.StaticText(parent, wx.ID_ANY, "Comments:")
        self.te7 = wx.TextCtrl(parent, wxID_Comments, style=wx.TE_MULTILINE)
        
        #to-do: Version list
        versionlst=["3.1.1"]
        self.lb8 = wx.StaticText(parent, wx.ID_ANY, "Version:")
        self.te8 = wx.ComboBox(parent, wxID_Version, "3.1.1", size=(130, -1), choices=versionlst)
        
        # Save, Discard,
        self.save = wx.Button(parent,wxID_Save, "&Save")
        self.discard = wx.Button(parent,wxID_Discard, "Discard")
        self.new = wx.Button(parent,wxID_New, "&New...")
        self.delete = wx.Button(parent,wxID_Delete, "Delete")
        self.close = wx.Button(parent,wxID_Close, "Close")
        
        self.save.Disable()
        self.discard.Disable()
        self.delete.Disable()
        
       
        #boxsizer
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        #Dataset
        hbox.Add(self.te1, 0, wx.ALL,5)
        #Class
        hbox.Add(self.lb3, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL,5)
        hbox.Add(self.te3, 0, wx.ALL,5)
        #Purpose
        hbox.Add(self.lb5, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL,5)
        hbox.Add(self.te5, 0, wx.ALL,5)
        #Version
        hbox.Add(self.lb8, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL,5)
        hbox.Add(self.te8, 0, wx.ALL,5)
        
        
        #FlexGridSizer
        fgs = wx.FlexGridSizer(4,2,5,5)
        fgs.AddMany([(self.lb1, 0, wx.ALIGN_RIGHT | wx.LEFT | wx.TOP, 5), (hbox, 0, wx.EXPAND),
                     (self.lb2, 0, wx.ALIGN_RIGHT | wx.LEFT | wx.TOP, 5), (self.te2, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5),
                     (self.lb4, 0, wx.ALIGN_RIGHT | wx.LEFT | wx.TOP, 5), (self.te4, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5),
                     (self.lb6, 0, wx.ALIGN_RIGHT | wx.LEFT | wx.TOP, 5), (self.te6, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5),
                     (self.lb7, 0, wx.ALIGN_RIGHT | wx.LEFT | wx.TOP, 5), (self.te7, 1, wx.EXPAND | wx.ALL, 5),
                    ])
        fgs.AddGrowableRow(4, 1)
        fgs.AddGrowableCol(1, 1)
        
        #boxsizer
        hbox_btn = wx.BoxSizer(wx.HORIZONTAL)
        hbox_btn.Add(self.save, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        hbox_btn.Add(self.discard, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        hbox_btn.Add(self.new, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        hbox_btn.Add(self.delete, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        hbox_btn.Add(self.close, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        
        # static line
        #self.staticline = wx.StaticLine(parent)
        
        # StaticBoxSizer
        # jowang added on 2008-07-08
        staticbox = wx.StaticBox(parent, id=wx.ID_ANY, label="Edit Dataset Metadata:")
        staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
        staticboxsizer.Add(fgs, 6, wx.EXPAND | wx.ALL, 5)
        
        #vertical boxsizer
        vbox = wx.BoxSizer(wx.VERTICAL)
        #vbox.Add(fgs, 6, wx.EXPAND | wx.ALL, 5)
        #vbox.Add(self.staticline, 0, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.ALL, 5)
        vbox.Add(staticboxsizer, 6, wx.EXPAND | wx.ALL, 5)
        vbox.Add(hbox_btn, 1, wx.ALIGN_RIGHT | wx.ALL, 5)
        
        parent.SetSizer(vbox)
